<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>在线交流信息</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <style>
        .nx-nav-container ul{
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }
        .nx-nav-container ul li{
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }
        .nx-nav-container a{
            color: #FFFFFF;
        }
        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }
        .left-box{
            width: 100%;
            height: 400px;
            background-color: #FFFFFF;
        }
        .img-item-box{
            width: 100%;
            height: 90px;
            margin-top: 10px;
        }
        .right-box{
            width: 100%;
            height: 400px;
            background-color: #FFFFFF;
        }

        .right-title{
            font-size: 20px;
            font-weight: bold;
        }
        .right-box li{
            padding: 10px 40px;
        }
        .praise{
            cursor: pointer;
            font-size: 20px;
            margin-left: 10px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div class="nx-header">
        <div style="display: flex;width: 100%;height: 30px;line-height: 30px;background-color: #eee;">
            <div style="flex: 5;padding: 0 10px; color: orangered;">
                欢迎访问 电影订票购票系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您： {{user.name}}
                <a style="margin-left: 30px;color: blue;" href="javascript:void(0);" @click="logout">退出</a>
            </div>
        </div>
    </div>
    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px;position: relative;">
            <img src="img/logo1.png" style="width: 40px;position: absolute;top: 20px;">
            <b style="margin-left: 45px;font-size:25px;text-shadow: 5px 5px 3px #888888">电影订票购票系统</b>
        </div>
    </div>

    <div class="nx-nav-container" style="height: 45px;background-color: black;">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li><a href="advertiserInfo.html">公告信息</a></li>
            <li class="active"><a href="messageInfo.html">在线交流信息</a></li>
            <li><a href="linkInfo.html">友情链接</a></li>
            <li><a href="cartInfo.html">收藏栏信息</a></li>
            <li><a href="orderInfo.html">订单信息</a></li>
            <li><a href="commonInfo.html">评价信息</a></li>
            <li><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li v-if="!isLogin"><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li v-if="!isLogin"><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>

    <div class="container" style="margin-top: 20px;">
        <div class="row">
            <div class="col-md-12">
                <h5>发表一下你的看法</h5>
        </div>
            <div class="col-md-12"style="margin-top: 10px">
                <textarea id="message-text"style="resize: none;width: 100%"></textarea>
                </div>
            <div class="col-md-12"style="text-align: right">
                 <button class=" btn btn-primary"@click="submitMessage">发送</button>
            </div>
        </div>
        <div class="row">
            <div style="background-color: white;min-height: 300px">
                <div style="width: 100%;height: 50px;background-color: #ddd;line-height: 50px;margin: 30px 0">
                    <span style="font-weight: bold;margin-left: 20px;font-size: 16px;">看看大家都在聊什么 （{{totalMessage}}）</span>
                </div>
                <div v-for="item in messages" class="row">
                    <div class="col-md-1" style="text-align: right">{{item.name}}</div>
                    <div class="col-md-10">
                        <div class="row" style="padding: 0 40px">
                            <div class="col-md-9" style="text-align: justify;">{{item.content}}</div>
                            <div class="col-md-3" >
                                <span style="color: #888888">{{item.time}}</span>
                            </div>
                            <div style="color: #888"v-for="child in item.children">
                                <div class="col-md-12" style="margin-top:10px;">{{child.name}}</div>
                                <div class="col-md-9" style="text-align: justify;">{{child.content}}</div>
                                <div class="col-md-3" >
                                    {{child.time}}
                                </div>
                            </div>

                            <div class="col-md-6"style="margin-top: 10px">
                                <input type="text"class="form-control" style="width: 80%;display: inline-block;"v-model="item.replyText">
                                <button class="btn btn-sm" @click="reply(item.id,item.replyText)">回复</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12"><hr style="margin: 10px 0"/> </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/swiper-5.4.5/swiper.min.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>
<script>
    new Vue({
        el: "#wrapper",
        data: {
            user: {}, // 当前登录用户
            isShow: false, // 是否显示进入后台
            isLogin: false, // 是否登录
            mssages:[],      //在线交流列表
            totalMessage: 0,  //评价总数
        },
        created: function () {
            // 查询权限
            axios.get('/auth').then(res => {
                if (res.data.code == '0') {
                    this.user = res.data.data;
                    // 若是管理员
                    if (this.user.level === 1) {
                        // 显示可以进入后台
                        this.isShow = true;
                    }
                    this.isLogin = true;
                }
            });
            this.loadMessages();
        },
        methods: {
            logout(){
                axios.get('/logout').then(res =>{
                    if(res.data.code === '0'){
                        location.href = '/front/index.html';
                    }else{
                        alert(res.data.msg);
                    }
                });
            },
            //加载在线交流列表
            loadGoodsInfo(){
                axios.get("/messageInfo/").then(res =>{
                    if (res.data.code === '0') {
                        this.messages = res.data.data;
                        this.totalMessage = this.messages.length;
                } else {
                    alert(res.data.msg);
                }
                });
            },
            //发表评论
            submitMessage(){
                let user= this.user;
                if(!user||!user.name){
                    alert('请先登录');
                    return;
                }
                let data={};
                let content=$('#message-text').val();
                if(!content){
                    alert('请输入内容');
                    return;
                }
                data.content=content;
                data.name=user.name;
                axios.post("/messageInfo/",data).then(res =>{
                    $('#message-text').val('');
                    alert('留言成功');
                    this.loadMessages();
                });
            },
            //回复
            reply(id,content){
                let user= this.user;
                if(!user||!user.name){
                    alert('请先登录');
                    return;
                }
                let data={};
                if(!content){
                    alert('请输入内容');
                    return;
                }
                data.content=content;
                data.name=user.name;
                data.parentId=id;
                axios.post("/messageInfo/",data).then(res =>{
                    alert('留言成功');
                    this.loadMessages();
                });
    }
        }
    });
</script>
</body>
</html>